﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DGSFramework;

namespace Framework
{
    public partial class Site : System.Web.UI.MasterPage
    {
        public DGSFrameworkEntities entity = new DGSFrameworkEntities();
        public List<udv_Categories> allCate = new List<udv_Categories>();
        public List<udv_Articles> allArt = new List<udv_Articles>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadCacheCategory();
                //LoadMenu();
            }
        }
       
        public void SetLanguage(object sender, EventArgs e)
        {
            if (Globals.CheckRewriteUrl() == false)
            {
                Session["language"] = ((ImageButton)sender).Attributes["rel"].ToString();
                Response.Redirect(Request.RawUrl);
            }
            else
            {
                Session["language"] = ((ImageButton)sender).Attributes["rel"].ToString();
                if (Request.Url.LocalPath.ToLower().Contains("default.aspx"))
                {
                    Response.Redirect(ResolveUrl("~/"));
                }
                else
                {
                    //Response.Redirect(ResolveUrl("~/"));
                    //Response.Redirect(Request.ServerVariables["HTTP_X_REWRITE_URL"]);
                    if (Request.ServerVariables["HTTP_X_REWRITE_URL"] != null)
                        Response.Redirect(Request.ServerVariables["HTTP_X_REWRITE_URL"]);
                    else
                        Response.Redirect(Request.RawUrl);
                }
            }
        }
        public void LoadCacheCategory()
        {
            if (Cache["Category"] == null)
            {
                Cache["Category"] = allCate = entity.udv_Categories.ToList();
            }
            else
            {
                allCate = (List<udv_Categories>)Cache["Category"];
            }
        }
      
        //public void LoadMenu()
        //{
        //    var parentMenu = allCate
        //        .Where(ca => (ca.ParentID == ConfigPaths.Category_Article_ID || ca.ParentID == ConfigPaths.Category_Product_ID) && ca.IsActive == true)
        //        .OrderBy(ca => ca.DisplayOrder)
        //        .ThenByDescending(ca => ca.AddedDate)
        //        .ToList();
        //    rptMenu.DataSource = parentMenu;
        //    rptMenu.DataBind();
        //}
    }
}